﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace thinger.EventApp
{
    public delegate void ReceiveDelegate(string data);
    public partial class FrmMain : Form
    {
        public FrmMain()
        {
            InitializeComponent();
        }
        List<Form> formList = new List<Form>();
        //【2】编写具体方法（事件方法）【接受者】
        private void ReceiveMsg(string data)
        {
            this.txtReceiveMsg.Text += data + "\r\n";
        }

        private void btnCreate_Click(object sender, EventArgs e)
        {
            for (int i = 1; i < 4; i++)
            {
                FrmChild frm = new FrmChild(i);
                frm.Show();

                frm.EventChildReveice += ReceiveMsg;
                formList.Add(frm);
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            foreach (FrmChild item in formList)
            {
                item.EventChildReveice -= ReceiveMsg;
            }
        }
    }
}
